Skip to content

refactor(ui): WebUI modernization PR5 — ES module split - #113

Closed
jkyberneees wants to merge 1 commit into
feat/webui-modernization-4from
feat/webui-modernization-5
Closed

refactor(ui): WebUI modernization PR5 — ES module split#113
jkyberneees wants to merge 1 commit into
feat/webui-modernization-4from
feat/webui-modernization-5

Conversation

@jkyberneees

Copy link
Copy Markdown
Contributor

Summary

Fifth PR of the WebUI modernization roadmap — Phase 3a: ES-module split. Stacked on #112 (feat/webui-modernization-4). Pure re-architecture: zero behavior, styling, or protocol changes.

The 2,408-line app.js IIFE (with ~40 mutable globals and ~50 functions, inline onclick handlers everywhere, and a monkey-patched addMessage) becomes native ES modules under cmd/odek/ui/js/ — still no build step, no dependencies, still embedded via embed.FS:

Module Responsibility
net.js Import-free leaf: getWsToken, apiHeaders
dom.js Import-free leaf: all getElementById refs
state.js Single mutable S object holding every former global (live-binding friendly); kode_*odek_* migration; session-token persistence incl. ensureSessionToken
utils.js escape/format helpers, clipboard, toast, scroll helpers, pruneMessages, small DOM toggles (showCancel/hideCancel/scrollToBottom/toggleShortcuts — placed here to keep the import graph acyclic)
markdown.js markdownToHtml verbatim (tokenizer rewrite is the next PR)
render.js Streaming, thinking, tool blocks, sub-agent cards, session-history rendering, copy/collapse, loading indicator, resetTurnState
approvals.js Full approval flow (queue, cards, friction gate, keyboard listener)
sessions.js Sidebar (list, rename/delete, load/render, search, toggle)
input.js Send, history, @-completion, attachments, drag-drop, auto-resize
ws.js connect() + the full WS event switch + event handlers
main.js Init sequence, theme, model picker, shortcuts, global keydown

ui/app.js is now a 4-line entry importing ./js/main.js; index.html loads it with type="module".

Inline handlers eliminated. Every onclick/onchange attribute (index.html + generated HTML) and every window.foo = export is gone, replaced by addEventListener and a single click-delegation listener on #messages (tool blocks, thinking toggles, sub-agent details, result expanders, code/message copy, collapse toggles). This unblocks the strict CSP in the next PR. The addMessage monkey-patch was dissolved into direct calls.

Server route: serve.go gains a sanitized /js/<file>.js route (rejects .., subdirectories, non-.js) serving from the embedded ui/js/.

Verification

  • node --check on all 12 files ✅; no leftover inline handlers or unqualified old globals ✅
  • go build, go vet, full cmd/odek test suite ✅
  • Smoke test of odek serve: /, /app.js, all 9 module files → 200; /js/evil.txt → 404; traversal rejected ✅

Split the ~2.4k-line app.js IIFE into native ES modules under
cmd/odek/ui/js/ (no build step, no dependencies). app.js stays the
/app.js entry and now just imports ./js/main.js.

- js/state.js: single mutable state object S (all former module-level
  globals) + session-token persistence helpers
- js/dom.js / js/net.js: import-free leaves (getElementById refs,
  getWsToken/apiHeaders)
- js/utils.js / js/markdown.js: pure helpers and markdownToHtml
- js/render.js: streaming, thinking, tool blocks, sub-agents, session
  history, collapse/copy, loading indicator; addMessage monkey-patch
  dissolved into direct addCopyButton/checkCollapse calls
- js/approvals.js / js/sessions.js / js/input.js / js/ws.js / js/main.js:
  approval queue, sidebar, prompt/attachments/@-completion, WebSocket
  dispatch, init sequence
- All inline onclick/onchange handlers (index.html and generated HTML)
  replaced with addEventListener / click delegation on #messages;
  window.* exports removed
- serve.go handleStatic: sanitized /js/<file>.js route (rejects ..,
  subdirs, non-.js) served from the embedded uiFS
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
odek 2f2968f Commit Preview URL

Branch Preview URL
Jul 26 2026, 01:12 PM

@jkyberneees

Copy link
Copy Markdown
Contributor Author

Superseded: this stacked chain was merged directly into main (merge commit 9ae5e46), together with #109. All changes from this PR are on main.

@jkyberneees
jkyberneees deleted the feat/webui-modernization-5 branch July 26, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant